package com.yss.common.core.enums;

import com.yss.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 需要替换版本号的表名
 *
 * @author lsl
 */
@Getter
@AllArgsConstructor
public enum TableVersionEnum implements BaseEnum<String> {
    /**
     * 用到系统的表名
     */
    REPORT_WORLD_CUSTOMER("REPORT_WORLD_CUSTOMER", "REPORT_WORLD_CUSTOMER"),
    REPORT_WORLD_DATA_CUSTOMER("REPORT_WORLD_DATA_CUSTOMER", "REPORT_WORLD_DATA_CUSTOMER"),
    REPORT_WORLD_DATA_DEMAND_BUG("REPORT_WORLD_DATA_DEMAND_BUG", "REPORT_WORLD_DATA_DEMAND_BUG"),
    REPORT_WORLD_DATA_MAP("REPORT_WORLD_DATA_MAP", "REPORT_WORLD_DATA_MAP"),
    REPORT_WORLD_DATA_MODULAR("REPORT_WORLD_DATA_MODULAR", "REPORT_WORLD_DATA_MODULAR"),
    REPORT_WORLD_DATA_REPORT("REPORT_WORLD_DATA_REPORT", "REPORT_WORLD_DATA_REPORT"),
    REPORT_WORLD_DATABASE("REPORT_WORLD_DATABASE", "REPORT_WORLD_DATABASE"),
    REPORT_WORLD_DATASQL("REPORT_WORLD_DATASQL", "REPORT_WORLD_DATASQL"),
    REPORT_WORLD_DEMAND_BUG_INFO("REPORT_WORLD_DEMAND_BUG_INFO", "REPORT_WORLD_DEMAND_BUG_INFO"),
    REPORT_WORLD_MODULAR("REPORT_WORLD_MODULAR", "REPORT_WORLD_MODULAR"),
    REPORT_WORLD_REPORT("REPORT_WORLD_REPORT", "REPORT_WORLD_REPORT"),
    REPORT_WORLD_TABLE("REPORT_WORLD_TABLE", "REPORT_WORLD_TABLE"),
    REPORT_WORLD_TABLE_DETAIL("REPORT_WORLD_TABLE_DETAIL", "REPORT_WORLD_TABLE_DETAIL"),
    REPORT_WORLD_TABLE_INDEXED("REPORT_WORLD_TABLE_INDEXED", "REPORT_WORLD_TABLE_INDEXED"),
    REPORT_WORLD_DATABASE_CHECK("REPORT_WORLD_DATABASE_CHECK", "REPORT_WORLD_DATABASE_CHECK"),
    REPORT_WORLD_DATABASE_DISPOSE("REPORT_WORLD_DATABASE_DISPOSE", "REPORT_WORLD_DATABASE_DISPOSE"),
   // REPORT_WORLD_TABLE_STANDARD_CHECK("REPORT_WORLD_TABLE_STANDARD_CHECK", "REPORT_WORLD_TABLE_STANDARD_CHECK"),
   // REPORT_WORLD_TABLE_DETAIL_STANDARD_CHECK("REPORT_WORLD_TABLE_DETAIL_STANDARD_CHECK", "REPORT_WORLD_TABLE_DETAIL_STANDARD_CHECK"),
    //报表世界ETL采集用到的表名，导出EXECL时候按照版本导出
    RW_DB_ETL_JOB_TASK("RW_DB_ETL_JOB_TASK", "RW_DB_ETL_JOB_TASK"),
    RW_DB_ETL_PARAMER_GROUP("RW_DB_ETL_PARAMER_GROUP", "RW_DB_ETL_PARAMER_GROUP"),
    RW_DB_ETL_CONFIG_DYNAMIC_FIELD("RW_DB_ETL_CONFIG_DYNAMIC_FIELD", "RW_DB_ETL_CONFIG_DYNAMIC_FIELD"),
    RW_DB_ETL_JOB_DETAIL("RW_DB_ETL_JOB_DETAIL", "RW_DB_ETL_JOB_DETAIL"),
    RW_DB_ETL_JOB("RW_DB_ETL_JOB", "RW_DB_ETL_JOB"),
    RW_DB_ETL_TEMPLATE("RW_DB_ETL_TEMPLATE", "RW_DB_ETL_TEMPLATE"),
    RW_DB_ETL_JOB_LEVEL("RW_DB_ETL_JOB_LEVEL", "RW_DB_ETL_JOB_LEVEL"),
    RW_DB_ETL_RESOURCE("RW_DB_ETL_RESOURCE", "RW_DB_ETL_RESOURCE"),
    RW_DB_ETL_JOB_TASK_DETAIL("RW_DB_ETL_JOB_TASK_DETAIL", "RW_DB_ETL_JOB_TASK_DETAIL"),
    RW_DB_ETL_RESOURCE_TYPE("RW_DB_ETL_RESOURCE_TYPE", "RW_DB_ETL_RESOURCE_TYPE"),
    RW_DB_ETL_RESOURCE_LABEL("RW_DB_ETL_RESOURCE_LABEL", "RW_DB_ETL_RESOURCE_LABEL"),
    RW_DB_ETL_JOB_RESOURCE("RW_DB_ETL_JOB_RESOURCE", "RW_DB_ETL_JOB_RESOURCE"),
    RW_DB_ETL_RESOURCE_LABEL_REL("RW_DB_ETL_RESOURCE_LABEL_REL", "RW_DB_ETL_RESOURCE_LABEL_REL"),
    //报表世界部署包用到的表名，导出部署包ZIP文件时候按照版本导出
    RW_DB_TC_REP_DATASET("RW_DB_TC_REP_DATASET", "RW_DB_TC_REP_DATASET"),
    RW_DB_TC_REP_PARA("RW_DB_TC_REP_PARA", "RW_DB_TC_REP_PARA"),
    RW_DB_TP_REP_BASIC_COL_MODEL("RW_DB_TP_REP_BASIC_COL_MODEL", "RW_DB_TP_REP_BASIC_COL_MODEL"),
    RW_DB_TP_REP_BASIC_INFO("RW_DB_TP_REP_BASIC_INFO", "RW_DB_TP_REP_BASIC_INFO"),
    RW_DB_TP_REP_BASIC_MICRO_VARIABLE("RW_DB_TP_REP_BASIC_MICRO_VARIABLE", "RW_DB_TP_REP_BASIC_MICRO_VARIABLE"),
    RW_DB_TP_REP_BASIC_PARAM("RW_DB_TP_REP_BASIC_PARAM", "RW_DB_TP_REP_BASIC_PARAM"),
    RW_DB_TP_REP_BASIC_REPORT_MODEL("RW_DB_TP_REP_BASIC_REPORT_MODEL", "RW_DB_TP_REP_BASIC_REPORT_MODEL"),
    RW_DB_TP_REP_BASIC_STYLE("RW_DB_TP_REP_BASIC_STYLE", "RW_DB_TP_REP_BASIC_STYLE"),
    RW_DB_TP_REP_BASIC_SUBMIT("RW_DB_TP_REP_BASIC_SUBMIT", "RW_DB_TP_REP_BASIC_SUBMIT"),
    RW_DB_TP_REP_BASIC_EXCELTEMPLATE("RW_DB_TP_REP_BASIC_EXCELTEMPLATE", "RW_DB_TP_REP_BASIC_EXCELTEMPLATE"),
    RW_DB_TP_GL_EXHIB_DATADICT("RW_DB_TP_GL_EXHIB_DATADICT", "RW_DB_TP_GL_EXHIB_DATADICT"),
    //报表世界规则用到的表名，导出EXECL时候按照版本导出
    RW_DB_R_CHECK_OBJECT("RW_DB_R_CHECK_OBJECT", "RW_DB_R_CHECK_OBJECT"),
    RW_DB_R_CHECK_IN_PARAMETER("RW_DB_R_CHECK_IN_PARAMETER", "RW_DB_R_CHECK_IN_PARAMETER"),
    RW_DB_R_SOURCE_TABLE("RW_DB_R_SOURCE_TABLE", "RW_DB_R_SOURCE_TABLE"),
    RW_DB_R_OBJECT_SOURCE_SQL_RELATION("RW_DB_R_OBJECT_SOURCE_SQL_RELATION", "RW_DB_R_OBJECT_SOURCE_SQL_RELATION"),
    RW_DB_R_CHECK_OBJECT_REL_MAPPING("RW_DB_R_CHECK_OBJECT_REL_MAPPING", "RW_DB_R_CHECK_OBJECT_REL_MAPPING"),
    RW_DB_R_CHECK_OBJECT_REL_GROUPBY("RW_DB_R_CHECK_OBJECT_REL_GROUPBY", "RW_DB_R_CHECK_OBJECT_REL_GROUPBY"),
    RW_DB_R_CHECK_RULE("RW_DB_R_CHECK_RULE", "RW_DB_R_CHECK_RULE"),
    RW_DB_R_RULE_LABEL_RELATION("RW_DB_R_RULE_LABEL_RELATION", "RW_DB_R_RULE_LABEL_RELATION"),
    RW_DB_R_RULE_LABEL("RW_DB_R_RULE_LABEL", "RW_DB_R_RULE_LABEL"),
    RW_DB_R_CHECK_SQL_OUT_PARAMETER("RW_DB_R_CHECK_SQL_OUT_PARAMETER", "RW_DB_R_CHECK_SQL_OUT_PARAMETER"),
    RW_DB_R_CONSTANT_TYPE("RW_DB_R_CONSTANT_TYPE", "RW_DB_R_CONSTANT_TYPE"),
    RW_DB_R_DATASET_PAR_FUNC_RELATION("RW_DB_R_DATASET_PAR_FUNC_RELATION", "RW_DB_R_DATASET_PAR_FUNC_RELATION"),
    RW_DB_R_CONSTANT("RW_DB_R_CONSTANT", "RW_DB_R_CONSTANT"),
    RW_DB_R_PARAMETER("RW_DB_R_PARAMETER", "RW_DB_R_PARAMETER"),
    RW_DB_R_PARAMETER_TYPE("RW_DB_R_PARAMETER_TYPE", "RW_DB_R_PARAMETER_TYPE"),
    RW_DB_R_FUNCTION("RW_DB_R_FUNCTION", "RW_DB_R_FUNCTION"),
    RW_DB_R_FUNCTION_TYPE("RW_DB_R_FUNCTION_TYPE", "RW_DB_R_FUNCTION_TYPE"),
    RW_DB_R_FUNC_IN_PARAMETER("RW_DB_R_FUNC_IN_PARAMETER", "RW_DB_R_FUNC_IN_PARAMETER"),
    RW_DB_R_FUNC_RETURN_PARAMETER("RW_DB_R_FUNC_RETURN_PARAMETER", "RW_DB_R_FUNC_RETURN_PARAMETER");
    private final String code;
    private final String desc;

    public static TableVersionEnum getEnum(String code) {
        return Arrays.stream(values()).filter(b -> b.code == code).findFirst().orElse(null);
    }

    public static String getEnumDesc(String code) {
        TableVersionEnum e = getEnum(code);
        return e != null ? e.desc : null;
    }

    /**
     * 按版本导出数据需要替换版本号的表
     *
     * @return
     */
    public static List<String> getVersionTables() {
        List<String> list = new ArrayList<>();
        for (TableVersionEnum tableVersionEnum : TableVersionEnum.values()) {
            if (StringUtils.isNull(tableVersionEnum)) {
                continue;
            }
            list.add(tableVersionEnum.getCode());
            list.add(tableVersionEnum.getCode().toLowerCase());
        }
        return list;

    }
}
